# -*- coding: utf-8 -*-
# author yzs
# date 2018-12-11
#
# Description
# 从一列数中筛除尽可能少的数使得从左往右看，这些数是从小到大再从大到小的。
# Input
# 输入时一个数组，数值通过空格隔开。
# Output
# 输出筛选之后的数组，用空格隔开。如果有多种结果，则一行一种结果。
# Sample Input 1 
# 1 2 4 7 11 10 9 15 3 5 8 6
# Sample Output 1
# 1 2 4 7 11 10 9 8 6
# 总结: 1、最大长度问题可以变为双边LIS问题，使用DP求解 2、所有解转换为最长公共子序列问题


def bi_list(data):
    n = len(data)
    dp_up = []
    dp_down = []
    dp_up.append(1)
    for i in range(1, n):
        max_i = 0
        for j in range(0, i):
            if data[i] > data[j] and dp_up[j] > max_i:
                max_i = dp_up[j]
        dp_up.append(max_i + 1)
    dp_down.append(1)
    for i in range(n - 2, -1, -1):
        max_i = 0
        for j in range(n - 1, i, -1):
            if data[i] > data[j] and dp_down[n - j - 1] > max_i:
                max_i = dp_down[n - j - 1]
        dp_down.append(max_i + 1)
    dp_down.reverse()
    max_index = 0
    max_len = 0
    for i in range(n):
        bi_list_len = dp_up[i] + dp_down[i]
        if max_len < bi_list_len:
            max_len = bi_list_len
            max_index = i
    #输出其中一个结果
    result_up = []
    tmp = dp_up[max_index]
    up_index = max_index
    for i in range(max_index-1, -1, -1):
        if dp_up[i] == tmp - 1 and data[i] < data[up_index]:
            result_up.append(data[i])
            tmp -= 1
            up_index = i
    result_down = []
    tmp = dp_down[max_index]
    down_index = max_index
    for i in range(max_index+1, n):
        if dp_down[i] == tmp - 1 and data[i] < data[down_index]:
            result_down.append(data[i])
            tmp -= 1
            down_index = i
    result_up.reverse()
    result_up.append(data[max_index])
    result_up.extend(result_down)
    print(" ".join(str(i) for i in result_up))


while True:
    try:
        data = list(map(int, input().strip().split()))
        bi_list(data)
    except EOFError:
        break
